package me.huanmeng.heater.signalling;

import lombok.Getter;
import me.huanmeng.heater.signalling.extra.SignallingExtraData;
import me.huanmeng.heater.signalling.extra.data.event.*;
import me.huanmeng.heater.signalling.extra.data.message.*;

import java.util.Arrays;
import java.util.Objects;

/**
 * 2021/9/28<br>
 * Heater<br>
 *
 * @author huanmeng_qwq
 */
@Getter
public enum ExtraType {
    TEXT(1, Text.class,true),
    IMAGE(2, Image.class),
    VIDEO(3, Video.class),
    FILE(4, File.class),
    MARKDOWN(9, KMarkdown.class),
    CARD(10, Card.class),
    UPDATE_MESSAGE("updated_message", UpdateMessage.class),
    DELETE_MESSAGE("deleted_message", DeletedMessage.class),
    CRAD_BUTTON_CLICK(ChannelType.PERSON, "message_btn_click", CardButtonClick.class),
    ADDED_REACTION("added_reaction", UserAddReaction.class),
    REMOVE_REACTION("deleted_reaction", UserRemoveReaction.class),
    GUILD_ADD_CHANNEL("added_channel", GuildAddChannel.class),
    GUILD_UPDATE_CHANNEL("updated_channel", GuildUpdateChannel.class),
    GUILD_REMOVE_CHANNEL("deleted_channel", GuildRemoveChannel.class),
    PINNED_MESSAGE("pinned_message", ChannelPinnedMessage.class),
    UNPINNED_MESSAGE("unpinned_message", ChannelUnPinnedMessage.class),
    USER_JOIN_CHANNEL("joined_channel", UserJoinedChannel.class),
    USER_QUIT_CHANNEL("exited_channel", UserQuitChannel.class),
    USER_UPDATE("user_updated", UserUpdate.class),
    GUILD_UPDATE("updated_guild",GuildUpdate.class),
    GUILD_DELETE("deleted_guild",GuildDelete.class),
    GUILD_BAN_USER("added_block_list",GuildBanUser.class),
    GUILD_UNBAN_USER("//todo ",GuildUnbanUser.class),
    UPDATE_PRIVATE_MESSAGE(ChannelType.PERSON,"updated_private_message",UpdatePrivateMessage.class),
    DELETE_PRIVATE_MESSAGE(ChannelType.PERSON,"deleted_private_message",DeletePrivateMessage.class),
    ADDED_PRIVATE_REACTION(ChannelType.PERSON,"private_added_reaction",UserPrivateAddReaction.class),
    REMOVE_PRIVATE_REACTION(ChannelType.PERSON,"private_deleted_reaction",UserPrivateRemoveReaction.class),
    USER_JOIN_GUILD("joined_guild",UserJoinGuild.class),
    USER_QUIT_GUILD("exited_guild",UserQuitGuild.class),
    GUILD_UPDATE_MEMBER("updated_guild_member",GuildUpdateMember.class),
    GUILD_MEMBER_ONLINE("guild_member_online",GuildMemberOnline.class),
    GUILD_MEMBER_OFFLINE("guild_member_offline",GuildMemberOffline.class),
    //todo role add
    ROLE_UPDATE("updated_role",RoleUpdate.class),
    ROLE_DELETE("deleted_role", RoleDelete.class),
    ;
    private final ChannelType channelType;
    private final Object id;
    private final Class<? extends SignallingExtraData<?>> clazz;
    private boolean both;

    ExtraType(ChannelType channelType, Object id, Class<? extends SignallingExtraData<?>> clazz) {
        this.channelType = channelType;
        this.id = id;
        this.clazz = clazz;
    }

    ExtraType(Object id, Class<? extends SignallingExtraData<?>> clazz) {
        this(ChannelType.GROUP, id, clazz);
    }

    ExtraType(Object id, Class<? extends SignallingExtraData<?>> clazz, boolean both) {
        this(ChannelType.GROUP, id, clazz);
        this.both = both;
    }

    public static ExtraType get(Object obj) {
        return Arrays.stream(values()).filter(e -> Objects.equals(obj, e.id)).findFirst().orElse(null);
    }

    public static ExtraType get(Object obj, ChannelType channelType) {
        return Arrays.stream(values()).filter(e -> Objects.equals(obj, e.id) && (e.both || channelType == e.channelType)).findFirst().orElse(null);
    }
}
